package com.hmall.common.config;


import com.hmall.common.interceptors.UserInfoInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@ConditionalOnClass(DispatcherServlet.class)
//此注解用于设置只有包含SpringMVC的核心AP:IDispatcherServlet的类可以生效本配置类的配置
// (没有SpringMVC就不能运行,网关就没有,不加此注解的话网关会报错,因为网关没有springMVC,也加载不了这个属于SpringMVC的配置类,网关本身也不需要这个)
public class MvcConfig implements WebMvcConfigurer {
    //配置拦截器,将其交给IOC管理,让其生效
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInfoInterceptor());
    }
}
